package com.example.webapp.service.impl;

import com.example.webapp.bean.Exam;
import com.example.webapp.dao.ExamDao;
import com.example.webapp.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements ExamService {
    private final ExamDao examDao;

    @Autowired
    public ExamServiceImpl(ExamDao examDao) {
        this.examDao = examDao;
    }

    @Override
    public void createExam(Exam exam) {
        examDao.save(exam);
    }

    @Override
    public void updateExam(Exam exam) {
        examDao.save(exam);
    }

    @Override
    public void deleteExam(Integer id) {
        examDao.deleteById(id);
    }

    @Override
    public List<Exam> getAllExams() {
        return examDao.findAll();
    }

    @Override
    public Exam getExamById(Integer id) {
        return examDao.findById(id).orElse(null);
    }

    @Override
    public Exam getExamByName(String name) {
        return examDao.findByName(name);
    }
}
